<?php
class memberstudentmod extends MY_Model{
	
	function memberstudentmod(){
		parent::__construct(
			"member_student",
			array(
				"id_member",
				"year",
				"faculty",
				"class"
			),
			array("id_member")
		);
	}
	
	function add($newData){
		$this->db->insert($this->table_name, $newData);
	}
	
	function update($id,$newData){
		$this->db->where($this->table_fields[0], $id);
		return $this->db->update($this->table_name, $newData);
	}
	
	function delete($ids){
		if (!is_array($ids)) $ids = array($ids);
    	foreach($ids as $pk) {
    		$this->db->or_where($this->table_fields[0], $pk);	
    	}
    	return $this->db->delete($this->table_name, $pk);
	}
	
	function remove($ids){
    	return $this->db->delete($this->table_name, array($this->table_fields[0]=>$ids));
    }
	
 	function get($id){
		return $this->db->get_where($this->table_name, array($this->table_fields[0]=>$id));
    }
    
	function get_record($limit=0,$offset=20){
		$this->db->limit($offset,$limit);
		return $this->db->get($this->table_name);
    }
    
	function get_record_unlimit(){
		return $this->db->get($this->table_name);
    }

	function get_where($where,$limit=0,$offset=20){
//    	return $this->db->get_where($this->table_name, $where, $limit, $offset);
		$this->db->like('id_member',$where,'match');
		$this->db->or_like('year',md5($where),'match');
		$this->db->or_like('faculty',$where,'both');
		$this->db->or_like('class',$where,'both');
		$this->db->limit($offset,$limit);
    	return $this->db->get($this->table_name);
    } 
    
	
}